package com.tencent.wxcloudrun.vo.request.card;

import com.tencent.wxcloudrun.domain.TUserCardApply;
import com.tencent.wxcloudrun.domain.TUserCardApplyImg;
import com.tencent.wxcloudrun.enums.CardApplyStatEnum;
import com.tencent.wxcloudrun.vo.BaseReqVo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.util.CollectionUtils;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author ZhaoZiYin
 * @Date 2025/4/22
 * @Description 申请卡片请求入参
 */
@Data
@EqualsAndHashCode(callSuper = true)
@ApiModel(value = "UserCardApplyReqVo", description = "申请卡片请求入参")
public class UserCardApplyReqVo extends BaseReqVo {

    @NotNull
    @ApiModelProperty("卡片序号")
    private Long cardId;

    @NotNull
    @ApiModelProperty("卡片数量")
    private Integer count;

    @ApiModelProperty("申请描述")
    private String memo;

    @ApiModelProperty("上传图片列表")
    private List<String> imgUrlList;

    public TUserCardApply build() {
        TUserCardApply apply = new TUserCardApply();
        apply.setUserId(this.getUserId());
        apply.setCardId(this.getCardId());
        apply.setCount(this.getCount());
        apply.setStatus(CardApplyStatEnum.TO_APPROVE.getValue());
        apply.setMemo(this.getMemo());
        apply.setCreatedBy(String.valueOf(this.getUserId()));
        apply.setCreatedTime(LocalDateTime.now());
        apply.setUpdatedBy(String.valueOf(this.getUserId()));
        apply.setUpdatedTime(LocalDateTime.now());
        return apply;
    }

    public List<TUserCardApplyImg> buildImg(Long userCardApplyId) {
        List<TUserCardApplyImg> applyImgList = new ArrayList<>();
        if (!CollectionUtils.isEmpty(this.getImgUrlList())) {
            for (String imgUrl : this.getImgUrlList()) {
                TUserCardApplyImg applyImg = new TUserCardApplyImg();
                applyImg.setUserCardApplyId(userCardApplyId);
                applyImg.setImgUrl(imgUrl);
                applyImg.setCreatedBy(String.valueOf(this.getUserId()));
                applyImg.setCreatedTime(LocalDateTime.now());
                applyImg.setUpdatedBy(String.valueOf(this.getUserId()));
                applyImg.setUpdatedTime(LocalDateTime.now());
                applyImgList.add(applyImg);
            }
        }
        return applyImgList;
    }

}
